home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / BTGETK.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  90 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)btgetk.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10. #ifdef AC_STRING
  11. #include <string.h>
  12. #endif
  13.  
  14. /* library headers */
  15. #include <blkio.h>
  16.  
  17. /* local headers */
  18. #include "btree_.h"
  19.  
  20. /*man---------------------------------------------------------------------------
  21. NAME
  22.      btgetk - read current btree key
  23.  
  24. SYNOPSIS
  25.      #include <btree.h>
  26.  
  27.      int btgetk(btp, buf)
  28.      btree_t *btp;
  29.      void *buf;
  30.  
  31. DESCRIPTION
  32.      The btgetk function reads the key from the current cursor
  33.      position in btree btp into buf.  buf must point to a storage area
  34.      as large as the key size for btp.
  35.  
  36.      btgetk will fail if one or more of the following is true:
  37.  
  38.      [EINVAL]       btp is not a valid btree pointer.
  39.      [EINVAL]       buf is the NULL pointer.
  40.      [BTELOCK]      btp is not read locked.
  41.      [BTENKEY]      The cursor is null.
  42.      [BTENOPEN]     btp is not open.
  43.  
  44. SEE ALSO
  45.      btcursor, btkeysize, btsearch.
  46.  
  47. DIAGNOSTICS
  48.      Upon successful completion, a value of 0 is returned.  Otherwise,
  49.      a value of -1 is returned, and errno set to indicate the error.
  50.  
  51. ------------------------------------------------------------------------------*/
  52. #ifdef AC_PROTO
  53. int btgetk(btree_t *btp, void *buf)
  54. #else
  55. int btgetk(btp, buf)
  56. btree_t *btp;
  57. void *buf;
  58. #endif
  59. {
  60.     /* validate arguments */
  61.     if (!bt_valid(btp) || buf == NULL) {
  62.         errno = EINVAL;
  63.         return -1;
  64.     }
  65.  
  66.     /* check if not open */
  67.     if (!(btp->flags & BTOPEN)) {
  68.         errno = EINVAL;
  69.         return -1;
  70.     }
  71.  
  72.     /* check locks */
  73.     if (!(btp->flags & BTRDLCK)) {
  74.         errno = BTELOCK;
  75.         return -1;
  76.     }
  77.  
  78.     /* initialize return value */
  79.     memset(buf, 0, btp->bthdr.keysize);
  80.  
  81.     /* read key value */
  82.     if (btp->cbtpos.node == NIL) {
  83.         errno = BTENKEY;
  84.         return -1;
  85.     }
  86.     memcpy(buf, bt_kykeyp(btp, btp->cbtnp, btp->cbtpos.key), btp->bthdr.keysize);
  87.  
  88.     return 0;
  89. }
  90.